{template 'common/header'}
{php echo $this -> set_tabbar($action);}
<input type="hidden" name="storeid" value="{$storeid}" />
{if $operation == 'display'}
<div class="main">
    <div class="panel panel-default">
        <div class="panel-body">
            <a class="btn btn-primary" href="{php echo $this->createWebUrl('password', array('op' => 'post'))}"><i class="fa fa-plus"></i> 添加消费密码</a>
        </div>
    </div>
    <form action="" method="post" class="form-horizontal form">
        <div class="panel panel-default">
            <div class="table-responsive panel-body">
                <table class="table table-hover">
                    <thead class="navbar-inner">
                    <tr>
                        <th style="width:60px;">编号</th>
                        <th>帐号</th>
                        <th>所属门店</th>
                        <th>操作权限</th>
                        <th style="width:80px;">状态</th>
                        <th style="min-width:100px;">编辑/审核/删除</th>
                    </tr>
                    </thead>
                    <tbody id="level-list">
                    {loop $password $row}
                    <tr>
                        <td>{$row['id']}</td>
                        <td>
                            {$row['username']}
                        </td>
                        <td>
                            {if empty($stores[$row['storeid']]['title'])}
                            门店总部                   　
                            {else}
                            {$stores[$row['storeid']]['title']}
                            {/if}
                        </td>
                        <td>
                            {if $row['consume']==1}
                            <span class="label label-success">消费</span>
                            {else}
                            <span class="label label-danger">消费</span>
                            {/if}
                            {if $row['recharge']==1}
                            <span class="label label-success">充值</span>
                            {else}
                            <span class="label label-danger">充值</span>
                            {/if}
                        </td>
                        <td>
                            {if $row['status']==1}
                            <span class="label label-success">开启</span>
                            {else}
                            <span class="label label-danger">关闭</span>
                            {/if}
                        </td>
                        <td>
                            <a class="btn btn-default btn-sm" href="{php echo $this->createWebUrl('password', array('op' => 'post', 'id' => $row['id']))}"><i class="fa fa-pencil"></i></a>
                            <a class="btn btn-default btn-sm" style="color:{if $row['status']==1}red{else}green{/if};" href="{php echo $this->createWebUrl('password', array('op' => 'check', 'id' => $row['id']))}" onclick="return confirm('确认操作吗？');return false;" title="{if $row['status']==1}暂停{else}启用{/if}"><i class="fa fa-{if $row['status']==1}stop{else}play{/if}"></i></a>
                            <a class="btn btn-default btn-sm" onclick="return confirm('确认删除吗？');return false;" href="{php echo $this->createWebUrl('password', array('op' => 'delete', 'id' => $row['id']))}"><i class="fa fa-times"></i></a>
                        </td>
                    </tr>
                    {/loop}
                    </tbody>
                </table>
            </div>
        </div>    　
    </form>
    {$pager}
</div>
{elseif $operation == 'post'}
<div class="main">
    <form action="" method="post" class="form-horizontal form" enctype="multipart/form-data" autocomplete = "off">
        <input type="hidden" name="parentid" value="{$parent['id']}" />
        <div class="panel panel-default">
            <div class="panel-heading">
                {$title}
            </div>
            <div class="panel-body">
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">帐号</label>
                    <div class="col-sm-9">
                        <input type="text" id="username" name="username" class="form-control" value="{$password['username']}" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">密码</label>
                    <div class="col-sm-9">
                        <input type="password" id="password" name="password" class="form-control" value="" placeholder="密码已保密，重新输入可重置密码" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">绑定门店</label>
                    <div class="col-sm-9">
                        <select class="form-control" name="store" id="store">
                            <option value="0">门店总部</option>
                            {loop $stores $item}
                            <option value="{$item['id']}" {if $item['id'] == $password['storeid']}selected{/if}>{$item['title']}</option>
                            {/loop}
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">消费确认</label>
                    <div class="col-sm-9">
                        <label for="consume_1" class="radio-inline"><input autocomplete="off" type="radio" name="consume" id="consume_1" value="1" {if $password['consume'] == 1 || empty($password['consume'])} checked="checked"{/if} /> 允许</label>
                        <label for="consume_0" class="radio-inline"><input autocomplete="off" type="radio" name="consume" id="consume_0" value="0" {if isset($password['consume']) && $password['consume'] == 0} checked="checked"{/if} /> 不允许</label>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">充值确认</label>
                    <div class="col-sm-9">
                        <label for="recharge_1" class="radio-inline"><input autocomplete="off" type="radio" name="recharge" id="recharge_1" value="1" {if $password['recharge'] == 1 || empty($password['recharge'])} checked="checked"{/if} /> 允许</label>
                        <label for="recharge_0" class="radio-inline"><input autocomplete="off" type="radio" name="recharge" id="recharge_0" value="0" {if isset($password['recharge']) && $password['recharge'] == 0} checked="checked"{/if} /> 不允许</label>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">状态</label>
                    <div class="col-sm-9">
                        <label for="status_1" class="radio-inline"><input autocomplete="off" type="radio" name="status" id="status_1" value="1" {if $password['status'] == 1 || empty($password['status'])} checked="checked"{/if} /> 开启</label>
                        <label for="status_0" class="radio-inline"><input autocomplete="off" type="radio" name="status" id="status_0" value="0" {if isset($password['status']) && $password['status'] == 0} checked="checked"{/if} /> 关闭</label>
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-12">
                <button type="submit" class="btn btn-primary col-lg-1" name="submit" value="提交">保存设置</button>
                <input type="hidden" name="token" value="{$_W['token']}" />
            </div>
        </div>
    </form>
</div>
<script type="text/javascript" src="./resource/script/kindeditor/kindeditor-min.js"></script>
<script type="text/javascript" src="./resource/script/kindeditor/lang/zh_CN.js"></script>
<link type="text/css" rel="stylesheet" href="./resource/script/kindeditor/themes/default/default.css" />
<script>
    var editor = KindEditor.editor({
        allowFileManager : true,
        uploadJson : "./index.php?act=attachment&do=upload",
        fileManagerJson : "./index.php?act=attachment&do=manager",
        afterUpload : function(url, data) {
        }
    });
    $("#upload-image-icon").click(function() {
        editor.loadPlugin("image", function() {
            editor.plugin.imageDialog({
                tabIndex : 1,
                imageUrl : $("#upload-image-url-icon").val(),
                clickFn : function(url) {
                    editor.hideDialog();
                    var val = url;
                    if(url.toLowerCase().indexOf("http://") == -1 && url.toLowerCase().indexOf("https://") == -1) {
                        var filename = /images(.*)/.exec(url);
                        if(filename && filename[0]) {
                            val = filename[0];
                        }
                    }
                    $("#upload-image-url-icon-old").val($("#upload-image-url-icon").val());
                    $("#upload-image-url-icon").val(val);
                    $("#upload-image-preview-icon").html('<img src="'+url+'" width="80px;" />');
                }
            });
        });
    });
</script>
{/if}
{template 'common/footer'}